package com.bianmaba.schedulings;

import com.bianmaba.jobs.DefaultJob;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;

/**
 * @program: samples
 * @description:
 * @author: Chenjiabin
 * @create: 2019/10/8 15:54
 **/
@Configuration
public class SimpleTriggerSchedule {

   // @Bean("simpleTriggerFactoryBean")
    public SimpleTriggerFactoryBean simpleTriggerFactoryBean() {
        JobDetail jobDetail = JobBuilder.newJob(DefaultJob.class)
                .withIdentity("simpleTriggerFactoryBean")
                .usingJobData("description", "简单的触发器，5秒一次，执行10次").build();

        SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
        trigger.setJobDetail(jobDetail);
        trigger.setRepeatInterval(5000);
        //重复执行多少次
        trigger.setRepeatCount(10);
        return trigger;
    }
}
